import Vue from 'vue'
import Vuex from 'vuex'
import actions from '../actions/custom'
import {
  UPDATE_SWITCH_SITE_STATUS, UPDATE_DATA_DICTCTIONARY,
  UPDATE_UPDATE_SMALL_AGE_CUSTOM_QUERY_CONDITION,
  UPDATE_UPDATE_LARGE_AGE_CUSTOM_QUERY_CONDITION,
  UPDATE_DAO_FONG_QUERY_CONDITION,
  UPDATE_TEAM_HIGH_SEAS_QUERY_CONDITION
} from '../mutation-types'
const localStorage = require('store')

Vue.use(Vuex)

const state = {
  'data_dictionary': {},
  'switch_site': !!localStorage.get('switch_site'),
  'small_age_custom_query_condition': {
    baby_birthday: [],
    insert_time: [new Date().getTime() - 3600 * 1000 * 24 * 30, new Date().getTime()],
    type: 'mobile_number',
    typeNumber: '',
    source_id: '',
    channel_id: '',
    team_id: '',
    page_size: 10,
    page_index: 1
  },
  'large_age_custom_query_condition': {
    baby_birthday: [],
    insert_time: [new Date().getTime() - 3600 * 1000 * 24 * 30, new Date().getTime()],
    type: 'mobile_number',
    typeNumber: '',
    source_id: '',
    channel_id: '',
    team_id: '',
    page_size: 10,
    page_index: 1
  },
  'df_clue_query_condition': {
    actual_time: [],
    type: 'mobile_number',
    typeNumber: '',
    suid: '',
    team_id: '',
    df_team_id: '',
    df_type: '',
    page_size: 10,
    page_index: 1
  },
  'team_high_seas_condition': {
    insert_time: [],
    team_id: null,
    source_id: '',
    channel_id: '',
    page_index: 1,
    page_size: 10
  }
}

const mutations = {
  [UPDATE_DATA_DICTCTIONARY] (state, data) {
    state['data_dictionary'] = data
  },
  [UPDATE_SWITCH_SITE_STATUS] (state, status) {
    localStorage.set('switch_site', status === true ? 1 : 0)
    state['switch_site'] = status
  },
  [UPDATE_UPDATE_SMALL_AGE_CUSTOM_QUERY_CONDITION] (state, data) {
    state['small_age_custom_query_condition'] = data
  },
  [UPDATE_UPDATE_LARGE_AGE_CUSTOM_QUERY_CONDITION] (state, data) {
    state['large_age_custom_query_condition'] = data
  },
  [UPDATE_DAO_FONG_QUERY_CONDITION] (state, data) {
    state['df_clue_query_condition'] = data
  },
  [UPDATE_TEAM_HIGH_SEAS_QUERY_CONDITION] (state, data) {
    state['team_high_seas_condition'] = data
  }
}

export default {
  state,
  mutations,
  actions
}
